package com.wtb.pub;

import com.wtb.utils.DateUtils;
import com.wtb.utils.MailUtils;

@SuppressWarnings("serial")
public class WtbException extends RuntimeException {
	private static int i = 0;
	public WtbException(Throwable cause) {
		super(cause);
	}

	public WtbException() {
		super();
	}

	public WtbException(String message, Throwable cause) {
		super(message, cause);
		try {
			StringBuilder exception = new StringBuilder();
			exception.append("发生异常的类："+cause+"\n"+"发生时间"+DateUtils.getDateString()+"\n"+"异常详细信息：");
			StackTraceElement[] messages = cause.getStackTrace();
			int length = messages.length;
			for (int i = 0; i < length; i++) {
				exception.append("\n").append(
						messages[i].toString());
			}
			i++;
			//DataCache.mailQeque.put("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
			if (i%50 == 0) {
				MailUtils.sendMail("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public WtbException(String message) {
		super(message);
		i++;
		if (i%50 == 0) {
			MailUtils.sendMail("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
		}
		/*try {
			DataCache.mailQeque.put("截止到:"+DateUtils.getDateString()+"为止,微同步已发生"+i+"次异常");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}*/
	}

}
